import {defineConfig} from 'vite'
const {resolve} = require('path')
import legacy from '@vitejs/plugin-legacy'


let proxy = {}
export default defineConfig({
  root: './src',
  base: './',
  server: {
    host: '0.0.0.0',
    port: 4000, // 设置服务启动端口号
    open: true, // 设置服务启动时是否自动打开浏览器
    proxy
  },
  // define: {
  //   wRes: {}
  // },
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src') // 设置 `@` 指向 `src` 目录
    }
  },
  build: {
    assetsInlineLimit:0,  //禁止资源转换为base64
    target:['es2015'],
    outDir: '../artifact',
    // assetsDir:'',
    rollupOptions: {
      input: {
        main: resolve(__dirname, './src/index.html'),
      }
    },
    lib: {
      entry: resolve(__dirname, 'lib/index.ts'),
      name: 'web-http',
      fileName: (format) => `web-http.${format}.js`
    },
  },
  plugins: [
    legacy({
      targets: ['chrome 52'],
      additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
      polyfills: ['es.promise.finally', 'es/map', 'es/set'],
      modernPolyfills: ['es.promise.finally']
    })
  ],
})

